﻿using System;
using System.IO;
using CommonFoundation.DataSource;
using CommonFoundation.DataModel;

namespace WHULive
{
    public class ConfigureAdmin
    {
        public static void GetConfigure()
        {
            if (!File.Exists(FilePath.GetInstance().ConfigureFilePath))
            {
                using (FileStream fileStream = File.Create(FilePath.GetInstance().ConfigureFilePath))
                {
                }
            }

            using (StreamReader streamReader = new StreamReader(FilePath.GetInstance().ConfigureFilePath))
            {
                while (true)
                {
                    string content = streamReader.ReadLine();

                    if (String.IsNullOrEmpty(content))
                    {
                        break;
                    }

                    string[] infos = content.Split(':');

                    if (infos.Length == 2)
                    {
                        switch (infos[0])
                        {
                            case "GoogleID" :
                                BindingSource.GetInstance().GoogleID = infos[1];
                                break;
                            case "StudentID" :
                                BindingSource.GetInstance().StudentID = infos[1];
                                break;
                            case "SaveFilePath" :
                                FilePath.GetInstance().SaveFilePath = infos[1];
                                break;
                        }
                    }
                }

            }
        }

        public static void SaveConfigure()
        {

            using (StreamWriter streamWriter = new StreamWriter(FilePath.GetInstance().ConfigureFilePath))
            {
                streamWriter.WriteLine(String.Format("{0}:{1}", "GoogleID", BindingSource.GetInstance().GoogleID));
                streamWriter.WriteLine(String.Format("{0}:{1}", "StudentID", BindingSource.GetInstance().StudentID));
                streamWriter.WriteLine(String.Format("{0}:{1}", "SaveFilePath", FilePath.GetInstance().SaveFilePath));
            }

            
        }
    }
}
